package com.gvitz.transaction.utils;

import java.util.ArrayList;


import com.gvitz.transaction.R;
import com.gvitz.transaction.models.Card;


import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;


/** Clase Adapter para ver la lista de Tarjetas
 * @author Orlando
 *
 */
public class TarjetasItemAdapter extends ArrayAdapter<Card> {
	private ArrayList<Card> Cards;
	private Activity act;
	Card tarjeta;

	public TarjetasItemAdapter(Context context, int textViewResourceId, ArrayList<Card> mCards,Activity activity) {
		super(context, textViewResourceId, mCards);
		this.Cards = mCards;
		this.act = activity;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.item_object, null);
		}
		
		tarjeta = Cards.get(position);
		
		if (tarjeta != null) {
						
			TextView nombre = (TextView) v.findViewById(R.id.nombre_item);

			if (nombre != null) {
				nombre.setText(tarjeta.getNombre());
			}
		}
		return v;
	}
	
	@Override
    public View getDropDownView(int position, View convertView, ViewGroup parent)
    {   // This view starts when we click the spinner.
        View row = convertView;
        if(row == null)
        {
            LayoutInflater inflater = act.getLayoutInflater();
            row = inflater.inflate(R.layout.dropdown_item, parent, false);
        }

        tarjeta = Cards.get(position);
        
		if (tarjeta != null) {
			
			TextView nombre = (TextView) row.findViewById(R.id.dropdown_item);

			if (nombre != null) {
				nombre.setText(tarjeta.getNombre());
			}
		}

        return row;
    }

}
